#include "Client.h"
#include "Utility.hpp"
Client::Client()
{
}

Client::~Client()
{
}

bool Client::Connect(const std::string& _ip, int port)
{
	if (_ip.empty() || port <= 0)
		return false;

	if (!CreateSocket())
	{
		LogPrint(LogType::ERR, "client create sock fail~");
		return false;
	}
	sockaddr_in addr = {};
	addr.sin_port = htons(port);
	addr.sin_family = AF_INET;
	addr.sin_addr.S_un.S_addr = inet_addr(_ip.c_str());
	int32_t result = ::connect(m_sockFd, (sockaddr*)&addr, sizeof(addr));
	return result == 0;
}

void Client::SendData(std::unique_ptr<NetPackArray>&& pack)
{
	if (nullptr == pack)
		return;
	::send(GetSocket(), pack->data(), pack->size(), 0);
	::send(GetSocket(), pack->data(), pack->size(), 0);
	::send(GetSocket(), pack->data(), pack->size(), 0);
	::send(GetSocket(), pack->data(), pack->size(), 0);
	::send(GetSocket(), pack->data(), pack->size(), 0);
}
